package com.elephant.core.schedule.scheduledexecutorservice;

import org.apache.commons.lang3.concurrent.BasicThreadFactory;

import java.util.Date;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author hai
 * @description
 * @date 10:53 2018/9/12
 */
public class TestScheduledExecutorService {

    public static void main(String[] args) {
        ScheduledExecutorService service = new ScheduledThreadPoolExecutor(1,
                new BasicThreadFactory.Builder().namingPattern("example-schedule-pool-%d").daemon(true).build());

        // 参数：1、任务体 2、首次执行的延时时间
        //      3、任务执行间隔 4、间隔时间单位
        service.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("task ScheduledExecutorService "+new Date());
            }
        },0,3,TimeUnit.SECONDS);
    }
}
